package com.ruoyi.common.utils;

import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

public class ModelMapperUtils {
    private static ModelMapper modelMapper = new ModelMapper();

    private ModelMapperUtils() {
    }

    public static <D> D strictMap(Object source, Class<D> destinationType) {
        return Objects.isNull(source) ? null : modelMapper.map(source, destinationType);
    }

    public static <D> List<D> strictMapList(Object source, Class<D> componentType) {
        if (Objects.isNull(source)) {
            return new ArrayList();
        } else {
            List<D> list = new ArrayList();
            List<Object> objectList = (List)source;
            Iterator var4 = objectList.iterator();

            while(var4.hasNext()) {
                Object obj = var4.next();
                list.add(modelMapper.map(obj, componentType));
            }

            return list;
        }
    }

    static {
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
    }
}
